// pages/uesename/username.js
const SERVER = require('../../utils/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    disabled: false,
    code: '获取验证码',
    input:'',
    codes:''
  },
  changes(e){//获取验证码内容
    this.setData({
      codes:e.detail.value
    })
    console.log(this.data.codes)
  },
  //点击登录
  user(){
    wx.request({//首页数据
      url: '' + SERVER.SERVER_DIMAIN + '/auth/mobile/token/sms?mobile=SMS@'+this.data.input+'&code='+this.data.codes+'&grant_type=mobile', 
      data: {
       
      },
      header: {
        'content-type': 'application/json' ,
        "TENANT-ID":"2",
        "Authorization":"Basic YXBwOmFwcA==",
        "DEVICE_TYPE":'IOS'
      },
      method: 'post',
      success: function (res) {
        console.log(res.statusCode)
        wx.setStorageSync('token', res.data.access_token)
   
        wx.switchTab({
          url:'../index/index'
                })
        
       
        
       
      }
    });
  },
  goGetCode:function(){
    var that = this;
    var time = 60;
    that.setData({
      code: '60秒后重发',
      disabled: true
    })
    var that=this
    wx.request({//首页数据
      url: '' + SERVER.SERVER_DIMAIN + '/admin/mobile/86/'+this.data.input, 
      data: {
     
      },
      header: {
        'content-type': 'application/json' 
      },
      method: 'get',
      success: function (res) {
    
      
        
       
      }
    });
    var Interval = setInterval(function() {
      time--;
     
      if (time>0){
        that.setData({
          code: time + '秒后重发'
        })
      }else{
        clearInterval(Interval);
        that.setData({
          code: '获取验证码',
          disabled: false
        })
      }
    },1000)},
    change(e){
      this.setData({
        input:e.detail.value
      })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})